package com.ltsw.mvpbaseproject.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.ltsw.mvpbaseproject.R;
import com.ltsw.mvpbaseproject.adapter.BaseAdapter;
import com.ltsw.mvpbaseproject.adapter.MyGridItemDecoration;
import com.ltsw.mvpbaseproject.adapter.MyLinearItemDecoration;
import com.ltsw.mvpbaseproject.adapter.ViewHolder;
import com.ltsw.mvpbaseproject.baseView.BaseActivity;
import com.ltsw.mvpbaseproject.presenter.RecyclerViewPresenter;

import java.util.ArrayList;
import java.util.List;

/**
 * RecyclerVIew万能适配器测试
 */
public class RecyclerViewActivity extends BaseActivity<RecyclerViewPresenter> {
    private RecyclerView recyclerView;
    private BaseAdapter<String> adapter;
    private List<String> list;

    @Override
    public void initView() {
        recyclerView = findViewById(R.id.recyclerView);
    }

    @Override
    public void initData() {
        list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add("数据数据" + i);
        }
//        MyGridItemDecoration divider = new MyGridItemDecoration.Builder(this)
//                .setHorizontalSpan(R.dimen.item_widght)
//                .setVerticalSpan(R.dimen.item_widght)
//                .setColorResource(R.color.colorAccent)
//                .setShowLastLine(false)
//                .build();
//        recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        MyLinearItemDecoration divider = new MyLinearItemDecoration.Builder(this)
                .setSpan(20f)
                .setColorResource(R.color.colorAccent)
                .setShowLastLine(true)
                .build();
        LinearLayoutManager myllManager = new LinearLayoutManager(this);
        myllManager.setOrientation(RecyclerView.VERTICAL);
        recyclerView.setLayoutManager(myllManager);
        recyclerView.addItemDecoration(divider);
        adapter = new BaseAdapter<String>(R.layout.recyclerview_item_demo, null, recyclerView, true) {
            @Override
            public void bind(ViewHolder holder, String item) {
                holder.setText(R.id.tvShow, item);
            }
        };
        adapter.setNewData(list);
    }

    @Override
    public RecyclerViewPresenter getPresenter() {
        return new RecyclerViewPresenter();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_recycler_view;
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, RecyclerViewActivity.class);
        context.startActivity(intent);
    }
}
